﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GalaktikaERPHelper.AtlantisDataTypeConversions.Extensions
{
    public static class DateTimeValueConvertMethods
    {
        public static DateTime ToDateTime(this int date)
        {
            if (date == 0)
                return DateTime.MinValue;

            var _date = date.IntToBytes();
            return new DateTime(
                (new byte[2] { _date[0], _date[1] }).ToInt(),
                _date[2].ToInt(),
                _date[3].ToInt());
        }
        public static int ToAtlDate(this DateTime value)
        {
            if (DateTime.Equals(value, DateTime.MinValue))
                return 0;

            byte[] dt = new byte[4];
            var year = value.Year.IntToBytes();
            dt[0] = year[2];
            dt[1] = year[3];
            dt[2] = value.Month.IntToBytes()[3];
            dt[3] = value.Day.IntToBytes()[3];

            return dt.ToInt();
        }

    }
}
